package ru.voronoy.thefifteen.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ru.voronoy.thefifteen.listeners.NameFrameListener;

public class NameFrame extends JFrame {
	private JLabel label;
	private JTextField field;
	private JButton button;
	private String time;

	public NameFrame(final String time) {
		this.time = time;

		this.setTitle("Введите имя");
		this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHTt);
		this.setLocationByPlatform(true);

		final JPanel panel = new JPanel(new GridBagLayout());

		label = new JLabel();
		label.setSize(LABEL_WIDTH, LABEL_HEIGHT);
		label.setText("Ваше имя:");
		panel.add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						0, 0, 0, 0), 0, 0));

		field = new JTextField(30);
		field.setText("");
		field.setSize(FIELD_WIDTH, FIELD_HEIGHT);
		panel.add(field, new GridBagConstraints(1, 0, 2, 1, 1, 0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						0, 0, 0, 0), 0, 0));

		button = new JButton();
		button.setText("OK");
		button.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
		button.addActionListener(new NameFrameListener(this, field, time));
		panel.add(button, new GridBagConstraints(1, 1, 1, 1, 1, 0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						1, 0, 0, 0), 0, 0));

		getContentPane().add(panel);

	}

	private static final int LABEL_HEIGHT = 10;
	private static final int LABEL_WIDTH = 50;
	private static final int FIELD_HEIGHT = 20;
	private static final int FIELD_WIDTH = 50;
	private static final int DEFAULT_WIDTH = 200;
	private static final int DEFAULT_HEIGHTt = 100;
	private static final int BUTTON_HEIGHT = 10;
	private static final int BUTTON_WIDTH = 20;
}
